              package com.java.diagnostics.visualizer.impl.axes;
              
              import com.java.diagnostics.visualizer.data.DataPoint;
              import com.java.diagnostics.visualizer.data.axes.Axis;
              import com.java.diagnostics.visualizer.data.axes.XDataAxis;
              import com.java.diagnostics.visualizer.impl.factory.LogFactory;
              import com.java.diagnostics.visualizer.impl.sources.SourceImpl;
              import com.java.diagnostics.visualizer.properties.OutputProperties;
              import com.java.diagnostics.visualizer.sources.Source;
              import java.util.logging.Logger;
              
              public class XDataAxisImpl extends DataAxisImpl
                implements XDataAxis
              {
                private static final Logger TRACE = LogFactory.getTrace(XDataAxisImpl.class);
              
                private final double[] xValues = new double[8];
                private int sequenceUID;
                private int sequenceHighWaterMark;
                private int nestDepth = 0;
                private static final int UNSET = -1;
                private SourceImpl source;
              
                public XDataAxisImpl(Axis axis, Source source, OutputProperties properties)
                {
                  this(axis, source, true, properties);
                }
              
                public XDataAxisImpl(Axis axis, Source source, boolean supportsNormalisation, OutputProperties properties)
                {
                  super(axis, supportsNormalisation, properties);
                  resetNesting();
                  clear();
                  this.source = ((SourceImpl)source);
                }
              
                public void setX(double x)
                {
                  this.sequenceUID += 1;
                  if (this.source != null) {
                    this.source.newSequenceUID(this.sequenceUID);
                  }
              
                  if (this.sequenceUID > this.sequenceHighWaterMark) {
                    this.sequenceHighWaterMark = this.sequenceUID;
                  }
              
                  checkNestDepth();
                  this.xValues[this.nestDepth] = x;
                }
              
                public double getX() {
                  checkNestDepth();
                  return this.xValues[this.nestDepth];
                }
              
                private void checkNestDepth() {
                  if (this.nestDepth < 0) {
                    this.nestDepth = 0;
                  }
                  if (this.nestDepth >= this.xValues.length)
                    this.nestDepth = (this.xValues.length - 1);
                }
              
                public int getSequenceUID()
                {
                  return this.sequenceUID;
                }
              
                public int checkSequenceUID(int previousSequence)
                {
                  if (this.sequenceUID <= previousSequence) {
                    this.sequenceUID = (previousSequence + 1);
                    if (this.source != null) {
                      this.source.newSequenceUID(this.sequenceUID);
                    }
                    this.sequenceHighWaterMark = this.sequenceUID;
                  }
                  return this.sequenceUID;
                }
              
                public void rollXBackwards()
                {
                  if (this.nestDepth < this.xValues.length)
                    this.nestDepth += 1;
                }
              
                public void rollXForward()
                {
                  if (this.nestDepth >= 0) {
                    this.nestDepth -= 1;
                  }
                  if (this.nestDepth > 0)
                    this.sequenceUID -= 1;
                }
              
                public boolean isNested()
                {
                  return this.nestDepth > 0;
                }
              
                public void resetNesting() {
                  this.nestDepth = 0;
                  this.sequenceUID = this.sequenceHighWaterMark;
                }
              
                private void clear() {
                  for (int i = 0; i < this.xValues.length; i++) {
                    this.xValues[i] = -1.0D;
                  }
              
                  this.sequenceUID = -1;
                  this.sequenceHighWaterMark = this.sequenceUID;
                  resetNesting();
                }
              
                protected double getRawValue(DataPoint dataPoint)
                {
                  return dataPoint.getRawX();
                }
              }

